package com.dyna.chat.service;

import com.dyna.chat.domain.resp.msg.ChatMessageResp;
import com.dyna.chat.domain.resp.ws.WSBaseResp;
import com.dyna.chat.domain.resp.ws.WSLoginSuccess;
import com.dyna.chat.domain.resp.ws.WSLoginUrl;
import com.dyna.chat.enums.WSRespTypeEnum;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
import org.springframework.stereotype.Component;

/**
 * Description: ws消息适配器
 * Author: <a href="https://github.com/zongzibinbin">abin</a>
 * Date: 2023-03-19
 */
@Component
public class WSAdapter {

    /**
     * 构建登录响应
     * @param wxMpQrCodeTicket 微信二维码票据
     * @return WSBaseResp<WSLoginUrl>
     */
    public static WSBaseResp<WSLoginUrl> buildLoginResp(WxMpQrCodeTicket wxMpQrCodeTicket) {
        WSBaseResp<WSLoginUrl> wsBaseResp = new WSBaseResp<>();
        wsBaseResp.setType(WSRespTypeEnum.LOGIN_URL.getType());
        wsBaseResp.setData(WSLoginUrl.builder().loginUrl(wxMpQrCodeTicket.getUrl()).build());
        return wsBaseResp;
    }

    /**
     * 构建无效token响应
     * @return WSBaseResp<WSLoginSuccess>
     */
    public static WSBaseResp<WSLoginSuccess> buildInvalidateTokenResp() {
        WSBaseResp<WSLoginSuccess> wsBaseResp = new WSBaseResp<>();
        wsBaseResp.setType(WSRespTypeEnum.INVALIDATE_TOKEN.getType());
        return wsBaseResp;
    }

    /**
     * 构建发送消息
     * @param msgResp ChatMessageResp
     * @return WSBaseResp
     */
    public static WSBaseResp<ChatMessageResp> buildMsgSend(ChatMessageResp msgResp) {
        WSBaseResp<ChatMessageResp> wsBaseResp = new WSBaseResp<>();
        wsBaseResp.setType(WSRespTypeEnum.MESSAGE.getType());
        wsBaseResp.setData(msgResp);
        return wsBaseResp;
    }

}
